// src\router\index.js
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Category from '../views/Category.vue'
import Cart from '../views/Cart.vue'
import User from '../views/User.vue'
import GoodDetail from '../views/GoodDetail.vue'
import Login from '../views/Login.vue'
import Setting from '../views/Setting.vue'
import ProductList from '../views/ProductList.vue'
import ProductDetail from '../views/ProductDetail.vue'

//使用createRouter 创建路由实例
const router = createRouter({
    history: createWebHashHistory(), //Hash模式：createWebHishHistory；History模式：createWebHistory
    routes: [
        {
            path: '/',
            redirect: '/home'   //重定向到 /home 路径下
        },
        {
            path: '/home',
            name: 'home',
            component: Home
        },
        {
            path: '/category',
            name: 'category',
            component: Category
        },
        {
            path: '/cart',
            name: 'cart',
            component: Cart
        },
        {
            path: '/user',
            name: 'user',
            component: User
        },
        {
            path: '/good-detail',
            name: 'GoodDetail',
            component: GoodDetail
        },
        {
            path: '/login',
            name: 'Login',
            component: Login
        },
        {
            path: '/setting',
            name: 'Setting',
            component: Setting
        },
        {
            path: '/product-list',
            name: 'ProductList',
            component: ProductList
        },
        {
            path: '/product-detail/:id',
            name: 'ProductDetail',
            component: ProductDetail
        },
        {
            path: '/address-edit',
            name: 'address-edit',
            component: () => import('../views/AddressEdit.vue')
        },
        {
            path: '/address',
            name: 'address',
            component: () => import('../views/Address.vue'),
        },
        {
            path: '/create-order',
            name: 'create-order',
            component: () => import('../views/CreateOrder.vue'),
        },
        {
            path: '/order',
            name: 'order',
            component: () => import('../views/Order.vue'),
        },
        {
            path: '/order-detail',
            name: 'order-detail',
            component: () => import('../views/OrderDetail.vue'),
        },
    ]
})

//抛出路由实例，在main.js中引用
export default router